package com.os.test.controller;

import com.os.test.model.User;
import com.os.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by songc on 2018/8/22.
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/user/index")
    public String index(){
        return "index.html";
    }

    @RequestMapping("/user/hello")
    public ModelAndView getIndex(){
        ModelAndView modelAndView = new ModelAndView("hello");
        User user = userService.selectUserByLoginCode("scl");
        modelAndView.addObject("hello", "hello Spring Boot!!!");
        modelAndView.addObject("user", user);
        return modelAndView;
    }

    @RequestMapping("/user/regist")
    public String regist(){
        return "regist";
    }

    @RequestMapping("/user/doRegist")
    public String doRegist(User user){
        System.out.println(user.getLoginCode());
        userService.regist(user);
        return "success";
    }

    @RequestMapping("/user/login")
    public String login(User user){
        user = userService.login(user.getLoginCode(), user.getUserPwd());
        if(user != null){
            return "success";
        }
        System.out.println(user);
        return "fail";
    }


}
